# -*- coding: utf-8 -*-
from flask import request
from db.client import cli
from utils.decorator import json_resp
from utils.tools import all_none
import sys

reload(sys)
sys.setdefaultencoding('utf8')
import timeFlag_bp


# def getTime():
#     note = request.args.get('note', None)
#     if all_none([note]):
#         return dict(success=False, msg='query parameter invalid.')
#
#     sql = "SELECT `导入日期` as times FROM log_information where `注释` = '{}';".format(note.encode('utf-8'))
#     res = cli.fetchone(sql)['times']
#     temp = '_' + res[0:10]
#     result = temp.replace("-", "_")
#     return dict(success=True, data=result)
def getTime(note):
    if all_none([note]):
        return dict(success=False, msg='query parameter invalid.')

    sql = "SELECT `表名后缀` as times FROM log_information where `注释` = '{}';".format(note.encode('utf-8'))
    res = cli.fetchone(sql)['times']
    temp = '_' + res
    # result = temp.replace("-", "_")
    return temp


def getNew():
    sql = "SELECT `表名后缀` as times FROM log_information order by `导入日期` desc limit 1;"
    res = cli.fetchone(sql)['times']
    temp = '_' + res
    # result = temp.replace("-", "_")
    return temp
